﻿Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Microsoft.Reporting.WebForms
Imports log4net

Partial Class Report_RP17
    Inherits System.Web.UI.Page

    Public ScriptText As String
    Dim Report As Object
    Private Shared logger As ILog = LogManager.GetLogger("Report_RP17")

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        'If Session("fundcenterS") = "" Then
        '    Session("fundcenterS") = "0011"
        '    Session("fundcenterE") = "0012"

        'End If

        'If Session("users") = "" Then
        '    Session("users") = "wassana"
        'End If
        'Session("year") = 2556
        'Session("version") = 2


        Getdata()


    End Sub


    Function Getdata() As Decimal


        Dim adapter As New Data_Report3TableAdapters.RP17TableAdapter
        Dim sql As String
        Dim dt As New Data_Report3.RP17DataTable


        'sql = " SELECT [BudgetDetails].[Id]"
        'sql += " ,[BudgetDetails].[PlanYear]"
        'sql += " ,[BudgetDetails].[BaseYear]"
        'sql += " ,[BudgetDetails].[Version]"
        'sql += " ,[BudgetDetails].[AssetNo]"
        'sql += " ,[BudgetDetails].[AssetDescription]"
        'sql += " ,[BudgetDetails].[AssetRowNo]"
        'sql += " ,[BudgetDetails].[OldAssetNo]"
        'sql += " ,Fundcenters.Description AS funcenter_name"
        'sql += " ,CASE ISNULL(BudgetDetails.[Project_ProjectCode],'') WHEN '' THEN 'งบประมาณประจำ' ELSE "
        'sql += " CASE LEFT(ISNULL(BudgetDetails.[Project_ProjectCode],''),1) WHEN 'P' THEN 'งบประมาณโครงการ'"
        'sql += " ELSE 'งบประมาณสนับสนุน' END"
        'sql += " END AS BudgetType"
        'sql += " ,STUFF((SELECT ',' + FundedProgram FROM FundedProgramAssets "
        'sql += " WHERE FundedProgramAssets.BudgetDetail_Id = BudgetDetails.[Id]"
        'sql += " ORDER BY FundedProgram  FOR XML PATH('')),1,1,'') AS IntOrder"
        'sql += " ,[BudgetDetails].[Amount]"
        'sql += " ,(ISNULL([BudgetDetails].[NewQuantity],0) + ISNULL([BudgetDetails].[ReplaceQuantity],0)) AS TotalQuantity"
        'sql += " ,[BudgetDetails].[PricePerUnit]"
        'sql += " ,[BudgetDetails].[Note]"
        'sql += " ,[BudgetDetails].[Identification]"
        'sql += " ,[BudgetDetails].[FormId]"
        'sql += " ,[BudgetDetails].[FndPrgGenFlag]"
        'sql += " ,[BudgetDetails].[FundedProgram]"
        'sql += " ,[BudgetDetails].[ActivityType_PlanYear]"
        'sql += " ,CASE ISNULL(BudgetDetails.[ActivityType_ActivityTypeCode],'') "
        'sql += " WHEN '' THEN BudgetDetails.[AssetNo] "
        'sql += " ELSE BudgetDetails.[ActivityType_ActivityTypeCode] "
        'sql += " END AS [ActivityType_ActivityTypeCode]"
        'sql += " ,CASE ISNULL(BudgetDetails.[ActivityType_ActivityTypeCode],'') "
        'sql += " WHEN '' THEN BudgetDetails.[AssetDescription] "
        'sql += " ELSE ActivityTypes.Description END AS ActTypeName"

        'sql += " ,[BudgetDetails].[FundCenter_FundCenterCode]"
        'sql += " ,[BudgetDetails].[FundCenter_PlanYear]"
        'sql += " ,[BudgetDetails].[Project_ProjectCode]"
        'sql += " ,Projects.Description AS projectName"
        'sql += " ,[BudgetDetails].[Project_PlanYear]"
        'sql += " ,[BudgetDetails].[Project_FundCenterCode]"
        'sql += " ,[BudgetDetails].[CmmtDetail_Id]"
        'sql += " ,[BudgetDetails].[Cmmt_CmmtCode]"
        'sql += " ,[BudgetDetails].[Cmmt_PlanYear]"
        'sql += " ,Cmmts.Description as cmmt_name"
        'sql += " FROM [dbo].[BudgetDetails]"
        'sql += "  INNER JOIN Cmmts ON BudgetDetails.[Cmmt_CmmtCode]=Cmmts.[CmmtCode] and BudgetDetails.[PlanYear]=Cmmts.[PlanYear]"
        'sql += " LEFT OUTER JOIN ActivityTypes ON [BudgetDetails].ActivityType_ActivityTypeCode = ActivityTypes.ActivityTypeCode"
        'sql += "  AND [BudgetDetails].ActivityType_PlanYear = ActivityTypes.PlanYear "
        'sql += " INNER JOIN Projects ON [BudgetDetails].[Project_ProjectCode] = Projects.ProjectCode "
        'sql += " AND [BudgetDetails].[Project_PlanYear] = Projects.PlanYear "
        'sql += " AND [BudgetDetails].[Project_FundCenterCode] = Projects.FundCenter_FundCenterCode"
        'sql += " INNER JOIN FundCenters ON BudgetDetails.[FundCenter_FundCenterCode] = Fundcenters.FundCenterCode"
        'sql += " AND BudgetDetails.[FundCenter_PlanYear] = FundCenters.PlanYear"



        'sql += " where BudgetDetails.PlanYear  = " & Session("year") & " "
        'sql += " and BudgetDetails.Version = '" & Session("version") & "' "
        'sql += " AND [BudgetDetails].ActivityType_PlanYear = " & Session("year") & " "
        'sql += " AND [BudgetDetails].Project_PlanYear = " & Session("year") & " "
        'If Session("FCTRmode") = "1" Then
        '    sql += " and  BudgetDetails.FundCenter_FundCenterCode IN (" & Session("FundcenterAll") & ") "
        'ElseIf Session("FCTRmode") = "2" Then
        '    sql += " and  BudgetDetails.FundCenter_FundCenterCode IN (" & Session("FundcenterAll") & ") "
        'End If


        'If Session("CmmtMode") = "1" Then
        '    If Val(Session("CmmtCodeS")) <> 0 And Val(Session("CmmtCodeE")) <> 0 Then
        '        sql += " and  Cmmts.CmmtCode  between " & Session("CmmtCodeS") & " and " & Session("CmmtCodeE")
        '    End If
        '    If Val(Session("CmmtCodeS")) <> 0 And Val(Session("CmmtCodeE")) = 0 Then
        '        sql += " and  Cmmts.CmmtCode = " & Session("CmmtCodeS")
        '    End If
        '    If Val(Session("CmmtCodeS")) = 0 And Val(Session("CmmtCodeE")) <> 0 Then
        '        sql += " and  Cmmts.CmmtCode = " & Session("CmmtCodeE")
        '    End If
        '    If Val(Session("CmmtCodeS")) = 0 And Val(Session("CmmtCodeE")) = 0 Then
        '        sql += " and  Cmmts.CmmtCode  between " & "'00000000'" & " and " & "'99999999'"
        '    End If
        'ElseIf Session("CmmtMode") = "2" Then
        '    If Session("CmmtParent") <> "" And Session("CmmtParent") <> "0" Then
        '        sql += "and BudgetDetails.Cmmt_CmmtCode in (select cmmt_cmmtcode from  cmmthierarchies where parentcmmthierarchy_id in (select id from cmmthierarchies "
        '        sql += " where id = " & Session("CmmtParent") & " or parentcmmthierarchy_id = " & Session("CmmtParent") & ")"
        '        sql += " or id in (select id from cmmthierarchies "
        '        sql += " where id = " & Session("CmmtParent") & " or parentcmmthierarchy_id = " & Session("CmmtParent") & ")"
        '        sql += ")"
        '    End If
        'End If



        'If Val(Session("ActivityS")) <> 0 And Val(Session("ActivityE")) <> 0 Then
        '    sql += "   and  BudgetDetails.ActivityType_ActivityTypeCode between " & Session("ActivityS") & " And " & Session("ActivityE")
        'End If

        'If Session("Project_ProjectCode") <> "" Then
        '    sql += " AND BudgetDetails.Project_ProjectCode IN ("
        '    Dim Numx As Array = Session("Project_ProjectCode").Split(",")
        '    For i = 0 To Numx.Length - 1
        '        If i <> 0 Then
        '            sql += ","
        '        End If
        '        sql += "'" & Numx(i).ToString & "'"

        '    Next
        '    sql += ") "
        'End If

        'Dim sql2 As String

        'sql2 = " SELECT [BudgetDetails].[Id]"
        'sql2 += " ,[BudgetDetails].[PlanYear]"
        'sql2 += " ,[BudgetDetails].[BaseYear]"
        'sql2 += " ,[BudgetDetails].[Version]"
        'sql2 += " ,[BudgetDetails].[AssetNo]"
        'sql2 += " ,[BudgetDetails].[AssetDescription]"
        'sql2 += " ,[BudgetDetails].[AssetRowNo]"
        'sql2 += " ,[BudgetDetails].[OldAssetNo]"
        'sql2 += " ,Fundcenters.Description AS funcenter_name"
        'sql2 += " ,CASE ISNULL(BudgetDetails.[Project_ProjectCode],'') WHEN '' THEN 'งบประมาณประจำ' ELSE "
        'sql2 += " CASE LEFT(ISNULL(BudgetDetails.[Project_ProjectCode],''),1) WHEN 'P' THEN 'งบประมาณโครงการ'"
        'sql2 += " ELSE 'งบประมาณสนับสนุน' END"
        'sql2 += " END AS BudgetType"
        'sql2 += " ,STUFF((SELECT ',' + FundedProgram FROM FundedProgramAssets "
        'sql2 += " WHERE FundedProgramAssets.BudgetDetail_Id = BudgetDetails.[Id]"
        'sql2 += " ORDER BY FundedProgram  FOR XML PATH('')),1,1,'') AS IntOrder"
        'sql2 += " ,[BudgetDetails].[Amount]"
        'sql2 += " ,(ISNULL([BudgetDetails].[NewQuantity],0) + ISNULL([BudgetDetails].[ReplaceQuantity],0)) AS TotalQuantity"
        'sql2 += " ,[BudgetDetails].[PricePerUnit]"
        'sql2 += " ,[BudgetDetails].[Note]"
        'sql2 += " ,[BudgetDetails].[Identification]"
        'sql2 += " ,[BudgetDetails].[FormId]"
        'sql2 += " ,[BudgetDetails].[FndPrgGenFlag]"
        'sql2 += " ,[BudgetDetails].[FundedProgram]"
        'sql2 += " ,[BudgetDetails].[ActivityType_PlanYear]"
        'sql2 += " ,CASE ISNULL(BudgetDetails.[ActivityType_ActivityTypeCode],'') "
        'sql2 += " WHEN '' THEN BudgetDetails.[AssetNo] "
        'sql2 += " ELSE BudgetDetails.[ActivityType_ActivityTypeCode] "
        'sql2 += " END AS [ActivityType_ActivityTypeCode]"
        'sql2 += " ,CASE ISNULL(BudgetDetails.[ActivityType_ActivityTypeCode],'') "
        'sql2 += " WHEN '' THEN BudgetDetails.[AssetDescription] "
        'sql2 += " ELSE ActivityTypes.Description END AS ActTypeName"

        'sql2 += " ,[BudgetDetails].[FundCenter_FundCenterCode]"
        'sql2 += " ,[BudgetDetails].[FundCenter_PlanYear]"
        'sql2 += " ,[BudgetDetails].[Project_ProjectCode]"
        'sql2 += " ,Projects.Description AS projectName"
        'sql2 += " ,[BudgetDetails].[Project_PlanYear]"
        'sql2 += " ,[BudgetDetails].[Project_FundCenterCode]"
        'sql2 += " ,[BudgetDetails].[CmmtDetail_Id]"
        'sql2 += " ,[BudgetDetails].[Cmmt_CmmtCode]"
        'sql2 += " ,[BudgetDetails].[Cmmt_PlanYear]"
        'sql2 += " ,Cmmts.Description as cmmt_name"
        'sql2 += " FROM [dbo].[BudgetDetails]"
        'sql2 += "  INNER JOIN Cmmts ON BudgetDetails.[Cmmt_CmmtCode]=Cmmts.[CmmtCode] and BudgetDetails.[PlanYear]=Cmmts.[PlanYear]"
        'sql2 += " LEFT OUTER JOIN ActivityTypes ON [BudgetDetails].ActivityType_ActivityTypeCode = ActivityTypes.ActivityTypeCode"
        'sql2 += " AND [BudgetDetails].ActivityType_PlanYear = ActivityTypes.PlanYear"
        'sql2 += " LEFT JOIN Projects ON [BudgetDetails].[Project_ProjectCode] = Projects.ProjectCode "
        'sql2 += " AND Projects.FundCenter_FundCenterCode IS NULL "
        'sql2 += " AND [BudgetDetails].[Project_PlanYear] = Projects.PlanYear "
        'sql2 += " INNER JOIN FundCenters ON BudgetDetails.[FundCenter_FundCenterCode] = Fundcenters.FundCenterCode"
        'sql2 += " AND BudgetDetails.[FundCenter_PlanYear] = FundCenters.PlanYear"



        'sql2 += " where BudgetDetails.PlanYear  = " & Session("year") & " and BudgetDetails.Version = '" & Session("version") & "'"
        'sql2 += " AND [BudgetDetails].ActivityType_PlanYear = " & Session("year") & " "
        'sql2 += " AND [BudgetDetails].Project_PlanYear = " & Session("year") & " "
        'sql2 += " AND [BudgetDetails].[Project_ProjectCode] IS NOT NULL AND [BudgetDetails].[Project_FundCenterCode] IS NULL "
        'If Session("FCTRmode") = "1" Then
        '    sql2 += " and  BudgetDetails.FundCenter_FundCenterCode IN (" & Session("FundcenterAll") & ") "
        'ElseIf Session("FCTRmode") = "2" Then
        '    sql2 += " and  BudgetDetails.FundCenter_FundCenterCode IN (" & Session("FundcenterAll") & ") "
        'End If


        'If Session("CmmtMode") = "1" Then
        '    If Val(Session("CmmtCodeS")) <> 0 And Val(Session("CmmtCodeE")) <> 0 Then
        '        sql2 += " and  Cmmts.CmmtCode  between " & Session("CmmtCodeS") & " and " & Session("CmmtCodeE")
        '    End If
        '    If Val(Session("CmmtCodeS")) <> 0 And Val(Session("CmmtCodeE")) = 0 Then
        '        sql2 += " and  Cmmts.CmmtCode = " & Session("CmmtCodeS")
        '    End If
        '    If Val(Session("CmmtCodeS")) = 0 And Val(Session("CmmtCodeE")) <> 0 Then
        '        sql2 += " and  Cmmts.CmmtCode = " & Session("CmmtCodeE")
        '    End If
        '    If Val(Session("CmmtCodeS")) = 0 And Val(Session("CmmtCodeE")) = 0 Then
        '        sql2 += " and  Cmmts.CmmtCode  between " & "'00000000'" & " and " & "'99999999'"
        '    End If
        'ElseIf Session("CmmtMode") = "2" Then
        '    If Session("CmmtParent") <> "" And Session("CmmtParent") <> "0" Then
        '        sql2 += "and BudgetDetails.Cmmt_CmmtCode in (select cmmt_cmmtcode from  cmmthierarchies where parentcmmthierarchy_id in (select id from cmmthierarchies "
        '        sql2 += " where id = " & Session("CmmtParent") & " or parentcmmthierarchy_id = " & Session("CmmtParent") & ")"
        '        sql2 += " or id in (select id from cmmthierarchies "
        '        sql2 += " where id = " & Session("CmmtParent") & " or parentcmmthierarchy_id = " & Session("CmmtParent") & ")"
        '        sql2 += ")"
        '    End If
        'End If



        'If Val(Session("ActivityS")) <> 0 And Val(Session("ActivityE")) <> 0 Then
        '    sql2 += "   and  BudgetDetails.ActivityType_ActivityTypeCode between " & Session("ActivityS") & " And " & Session("ActivityE")

        'End If

        'If Session("Project_ProjectCode") <> "" Then
        '    sql2 += " AND BudgetDetails.Project_ProjectCode IN ("
        '    Dim Numx As Array = Session("Project_ProjectCode").Split(",")
        '    For i = 0 To Numx.Length - 1
        '        If i <> 0 Then
        '            sql2 += ","
        '        End If
        '        sql2 += "'" & Numx(i).ToString & "'"

        '    Next
        '    sql2 += ") "
        'End If

        'sql += " UNION " + sql2

        'Add By Orn 18/08/2558
        sql = " SELECT [BudgetDetails].[Id]"
        sql += " ,[BudgetDetails].[PlanYear]"
        sql += " ,[BudgetDetails].[BaseYear]"
        sql += " ,[BudgetDetails].[Version]"
        sql += " ,[BudgetDetails].[AssetNo]"
        sql += " ,[BudgetDetails].[AssetDescription]"
        sql += " ,[BudgetDetails].[AssetRowNo]"
        sql += " ,[BudgetDetails].[OldAssetNo]"
        sql += " ,Fundcenters.Description AS funcenter_name"
        sql += " ,CASE ISNULL(BudgetDetails.[Project_ProjectCode],'') WHEN '' THEN 'งบประมาณประจำ' ELSE "
        sql += " CASE LEFT(ISNULL(BudgetDetails.[Project_ProjectCode],''),1) WHEN 'P' THEN 'งบประมาณโครงการ'"
        sql += " ELSE 'งบประมาณสนับสนุน' END"
        sql += " END AS BudgetType"
        sql += " ,STUFF((SELECT ',' + FundedProgram FROM FundedProgramAssets "
        sql += " WHERE FundedProgramAssets.BudgetDetail_Id = BudgetDetails.[Id]"
        sql += " ORDER BY FundedProgram  FOR XML PATH('')),1,1,'') AS IntOrder"
        sql += " ,[BudgetDetails].[Amount]"
        sql += " ,(ISNULL([BudgetDetails].[NewQuantity],0) + ISNULL([BudgetDetails].[ReplaceQuantity],0)) AS TotalQuantity"
        sql += " ,[BudgetDetails].[PricePerUnit]"
        sql += " ,[BudgetDetails].[Note]"
        sql += " ,[BudgetDetails].[Identification]"
        sql += " ,[BudgetDetails].[FormId]"
        sql += " ,[BudgetDetails].[FndPrgGenFlag]"
        sql += " ,[BudgetDetails].[FundedProgram]"
        sql += " ,[BudgetDetails].[ActivityType_PlanYear]"
        sql += " ,CASE ISNULL(BudgetDetails.[ActivityType_ActivityTypeCode],'') "
        sql += " WHEN '' THEN BudgetDetails.[AssetNo] "
        sql += " ELSE BudgetDetails.[ActivityType_ActivityTypeCode] "
        sql += " END AS [ActivityType_ActivityTypeCode]"
        sql += " ,CASE ISNULL(BudgetDetails.[ActivityType_ActivityTypeCode],'') "
        sql += " WHEN '' THEN BudgetDetails.[AssetDescription] "
        sql += " ELSE ActivityTypes.Description END AS ActTypeName"

        sql += " ,[BudgetDetails].[FundCenter_FundCenterCode]"
        sql += " ,[BudgetDetails].[FundCenter_PlanYear]"
        sql += " ,[BudgetDetails].[Project_ProjectCode]"
        sql += " ,Projects.Description AS projectName"
        sql += " ,[BudgetDetails].[Project_PlanYear]"
        sql += " ,[BudgetDetails].[Project_FundCenterCode]"
        sql += " ,[BudgetDetails].[CmmtDetail_Id]"
        sql += " ,[BudgetDetails].[Cmmt_CmmtCode]"
        sql += " ,[BudgetDetails].[Cmmt_PlanYear]"
        sql += " ,Cmmts.Description as cmmt_name"
        sql += " FROM [dbo].[BudgetDetails]"
        sql += "  INNER JOIN Cmmts ON BudgetDetails.[Cmmt_CmmtCode]=Cmmts.[CmmtCode] and BudgetDetails.[PlanYear]=Cmmts.[PlanYear]"
        sql += " LEFT OUTER JOIN ActivityTypes ON [BudgetDetails].ActivityType_ActivityTypeCode = ActivityTypes.ActivityTypeCode"
        sql += "  AND [BudgetDetails].ActivityType_PlanYear = ActivityTypes.PlanYear "
        sql += " INNER JOIN Projects ON [BudgetDetails].[Project_ProjectCode] = Projects.ProjectCode "
        sql += " AND [BudgetDetails].[Project_PlanYear] = Projects.PlanYear "
        sql += " INNER JOIN FundCenters ON BudgetDetails.[FundCenter_FundCenterCode] = Fundcenters.FundCenterCode"
        sql += " AND BudgetDetails.[FundCenter_PlanYear] = FundCenters.PlanYear"
        sql += " where BudgetDetails.PlanYear  = " & Session("year") & " "
        sql += " and BudgetDetails.Version = '" & Session("version") & "' "
        sql += " AND [BudgetDetails].Project_PlanYear = " & Session("year") & " "
        If Session("FCTRmode") = "1" Or Session("FCTRmode") = "2" Then
            sql += " and  BudgetDetails.FundCenter_FundCenterCode IN (" & Session("FundcenterAll") & ") "
        End If
        If Session("CmmtMode") = "1" Then
            If Val(Session("CmmtCodeS")) <> 0 And Val(Session("CmmtCodeE")) <> 0 Then
                sql += " and  Cmmts.CmmtCode  between " & Session("CmmtCodeS") & " and " & Session("CmmtCodeE")
            End If
            If Val(Session("CmmtCodeS")) <> 0 And Val(Session("CmmtCodeE")) = 0 Then
                sql += " and  Cmmts.CmmtCode = " & Session("CmmtCodeS")
            End If
            If Val(Session("CmmtCodeS")) = 0 And Val(Session("CmmtCodeE")) <> 0 Then
                sql += " and  Cmmts.CmmtCode = " & Session("CmmtCodeE")
            End If
            If Val(Session("CmmtCodeS")) = 0 And Val(Session("CmmtCodeE")) = 0 Then
                sql += " and  Cmmts.CmmtCode  between " & "'00000000'" & " and " & "'99999999'"
            End If
        ElseIf Session("CmmtMode") = "2" Then
            If Session("CmmtParent") <> "" And Session("CmmtParent") <> "0" Then
                sql += "and BudgetDetails.Cmmt_CmmtCode in (select cmmt_cmmtcode from  cmmthierarchies where parentcmmthierarchy_id in (select id from cmmthierarchies "
                sql += " where id = " & Session("CmmtParent") & " or parentcmmthierarchy_id = " & Session("CmmtParent") & ")"
                sql += " or id in (select id from cmmthierarchies "
                sql += " where id = " & Session("CmmtParent") & " or parentcmmthierarchy_id = " & Session("CmmtParent") & ")"
                sql += ")"
            End If
        End If
        If Session("ActivityTypeS") <> "" Or Session("ActivityTypeE") <> "" Then
            sql += " AND [BudgetDetails].ActivityType_PlanYear = " & Session("year") & " "
        End If
        If Session("ActivityTypeS") <> "" Then
            sql += " and BudgetDetails.ActivityType_ActivityTypeCode >= " & Session("ActivityTypeS")
        End If
        If Session("ActivityTypeE") <> "" Then
            sql += " and BudgetDetails.ActivityType_ActivityTypeCode <= " & Session("ActivityTypeE")
        End If
        If Session("Project_ProjectCode") <> "" Then
            sql += " AND BudgetDetails.Project_ProjectCode IN ("
            Dim Numx As Array = Session("Project_ProjectCode").Split(",")
            For i = 0 To Numx.Length - 1
                If i <> 0 Then
                    sql += ","
                End If
                sql += "'" & Numx(i).ToString & "'"
            Next
            sql += ") "
        End If
        adapter.GetDataByFilter(dt, sql)



        'Return 1
        'Exit Function

        Dim das As New DataSet
        das.DataSetName = "R01DS"
        dt.TableName = "R17DT"
        das.Tables.Add(dt)
        ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local
        'ReportViewer1.LocalReport.ReportPath = System.Environment.CurrentDirectory & "Report\R01.rdlc"
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", das.Tables("R17DT")))
        ReportViewer1.DocumentMapCollapsed = True

        Dim UserName As String = Session("users")
        Dim years As String = Session("year")
        Dim version As String = Session("version")
        'Dim users As String = Session("users")

        Dim p1, p2, p3 As ReportParameter
        p1 = New ReportParameter("year", years)
        p2 = New ReportParameter("version", version)
        p3 = New ReportParameter("username", UserName)

        ReportViewer1.LocalReport.SetParameters(p1)
        ReportViewer1.LocalReport.SetParameters(p2)
        ReportViewer1.LocalReport.SetParameters(p3)


        ReportViewer1.LocalReport.Refresh()


        'Response.Write(dt.Rows.Count & sql)
        Session("count") = dt.Rows.Count



        Return dt.Rows.Count

    End Function


    Public Function nPageNumber() As String
        Dim str As String
        str = Me.Report.Globals!PageNumber.ToString()
        Return str
    End Function

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Session("users") Is Nothing Then
            ScriptText = "<script> wclose();</script>"
        End If
    End Sub
End Class
